import { BasicColumn, FormSchema } from '/@/components/Table';
import { duplicateCheck } from '/@/views/system/user/user.api';

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'ruleName',
    width: 200,
    align: 'center',
  },
  {
    title: '编码',
    dataIndex: 'ruleCode',
    width: 200,
    align: 'center',
  },
  {
    title: '单据类型',
    dataIndex: 'billTypeName',
    width: 200,
    align: 'center',
  },
  {
    title: '实现类',
    dataIndex: 'ruleClass',
    width: 300,
    align: 'center',
  },
  {
    title: '参数',
    dataIndex: 'ruleParams',
    width: 200,
    align: 'center',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'ruleName',
    label: '名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'ruleCode',
    label: '编码',
    component: 'Input',
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'ruleName',
    label: '名称',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'ruleCode',
    label: '编码',
    component: 'Input',
    colProps: { span: 24 },
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
    dynamicRules: ({ model }) => {
      return [
        {
          required: true,
          validator: (_, value) => {
            return new Promise((resolve, reject) => {
              if (!value) {
                return reject('请输入编码！');
              } else resolve() 
              // let params = {
              //   tableName: 'sys_fill_rule',
              //   fieldName: 'rule_code',
              //   fieldVal: value,
              //   dataId: model.id,
              // };
              // duplicateCheck(params)
              //   .then((res) => {
              //     res.success ? resolve() : reject('编码已存在!');
              //   })
              //   .catch((err) => {
              //     reject(err.message || '校验失败');
              //   });
            });
          },
        },
      ];
    },
  },
  {
    field: 'ruleClass',
    label: '实现类',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
    dynamicDisabled:true
  },
  {
    field: 'billTypeId',
    label: '单据类型id',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
    show:false
  },
  {
    field: 'billTypeName',
    label: '单据类型',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
    slot:'billTypeSlot'
  },
  {
    field: 'ruleParams',
    label: '参数',
    colProps: { span: 24 },
    component: 'Input',
    slot:'ruleParamsSlot'
  },
];
